<template>
	<el-dialog :title="title" :visible.sync="visible" :before-close="handleClose">
		<el-form ref="form" :model="form" label-width="80px">
			<el-form-item label="角色名称">
				<el-input v-model="form.roleName"></el-input>
			</el-form-item>
			<el-form-item label="描述">
				<el-input v-model="form.description"></el-input>
			</el-form-item>
			<el-form-item label="激活标识">
				<el-input v-model="form.activeFlag"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="onSubmit">保存</el-button>
			</el-form-item>
		</el-form>
	</el-dialog>
</template>

<script>
	import { Message } from 'element-ui';
import { saveOrUpdateRole } from './api';
	export default {
		data() {
			return {
				form: {
					roleName: '',
					description: '',
					activeFlag: '',
				},
				title: '',
				visible: false,
			}
		},
		mounted(){
			console.log()
		},
		methods: {
			onSubmit() {
				let data = this.form;
				saveOrUpdateRole(data).then(res => {
					if(res.data.code == 0){
						this.title = '';
						this.form = {};
						this.visible = false;
						this.$emit('refresh')
						Message.success("保存成功");
					}else{
						Message.error(res.data.msg);
					}
				})
				console.log('submit!');
			},
			receiveValues(value){
				console.log(value)
				this.visible = value.visible;
				this.title = value.title;
				if(value.userForm != null){
					this.form = value.userForm;
				}
			},
			handleClose(done){
				this.title = '';
				this.form = {};
				this.visible = false
				this.$emit('refresh')
				done();
			}
		}
	}
</script>

<style>
</style>